<?php
	//-------------------------------------
		if($_POST['act'] == 'add' && !empty($_POST['submit'])){
			$param = $_POST;
			if(empty($param['spot_name']) || empty($param['address'])){
				admin_msg("module.php?m=spot&s=spot.php","请填写场馆信息");
				return false;
			}
			$param['add_time'] = time();
			$param['statu'] = isset($param['statu']) ? $param['statu'] : 0;

			$param['provinceid'] = !empty(getdistrictid($_SESSION['province'])) ? getdistrictid($_SESSION['province']) : 0;
			$param['cityid'] = !empty(getdistrictid($_SESSION['city'])) ? getdistrictid($_SESSION['city']) : 0;
			$param['areaid'] = !empty(getdistrictid($_SESSION['area'])) ? getdistrictid($_SESSION['area']) : 0;

			$insert_sql = "insert into ".SPOT." (`cat_id`,`pid`,`spot_name`,`picurl`,`tel`,`address`,`content`,`statu`,`add_time`,`seat_pic`,`seat_m_pic`,`provinceid`,`cityid`,`areaid`)
			values ('{$param['cat_id']}','{$param['pid']}','{$param['spot_name']}','{$param['picurl']}','{$param['tel']}','{$param['address']}',
			'{$param['content']}','{$param['statu']}','{$param['add_time']}','{$param['seat_pic']}','{$param['seat_m_pic']}','{$param['provinceid']}','{$param['cityid']}','{$param['areaid']}')";
			$db->query($insert_sql);
			$last_id = $db->lastid();
			if($last_id){
				msg("?m=spot&s=spot.php");
				return false;
			} else {
				msg("?m=spot&s=spot.php",'添加失败');
				return false;
			}

		}
		if($_POST['act'] == 'edit' && !empty($_POST['editid'])){
			$param = $_POST;
			$u_sql = "update ".SPOT." set cat_id='{$param['cat_id']}',pid='{$param['pid']}',spot_name='{$param['spot_name']}',picurl='{$param['picurl']}',tel='{$param['tel']}'
			 ,address='{$param['address']}',content='{$param['content']}',seat_pic='{$param['seat_pic']}',seat_m_pic='{$param['seat_m_pic']}',statu='{$param['statu']}' where id = '{$_POST['editid']}' ";
			if($db->query($u_sql)){
				msg("?m=spot&s=spot.php");
				return false;
			} else {
				msg("?m=spot&s=spot.php",'编辑失败');
				return false;
			}

		}

	$act = !empty($_GET['act']) ? $_GET['act'] : '';
	$edit_id = $_GET['editid'] * 1;
	if($_SESSION['province']){
		$psql = " and provinceid = ".getdistrictid($_SESSION['province']);
	}
	if($_SESSION['city']){
		$psql .= " and cityid = ".getdistrictid($_SESSION['city']);
	}
	if($_SESSION['area']){
		$psql .= " and areaid = ".getdistrictid($_SESSION['area']);
	}


	$c_sql = "select * from ".SPOTCAT." where statu = '1' $psql ";
	$db->query($c_sql);
	$cat_list = $db->getRows();

    $sql = "select * from ".SPOT." where id = '$edit_id' $psql ";
	$db->query($sql);
	$de = $db->fetchRow();

	include_once("footer.php");
	$tpl->assign("config",$config);
    $tpl->assign("lang",$lang);
	$tpl->assign("cat_list",$cat_list);
	$tpl->assign('act',$act);
	$tpl->assign('de',$de);
	$tpl->display("spot_opt.htm");


?>